home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / HEAP_UTL / TPSTACK / TPSTACK.ASM next >
Assembly Source File  |  1988-06-20  |  3KB  |  98 lines

  1. ;******************************************************
  2. ;                  TPSTACK.ASM 1.00
  3. ;               by TurboPower Software
  4. ;******************************************************
  5.  
  6. ;****************************************************** Equates
  7.  
  8. Ofst            EQU     (WORD PTR 0)
  9. Segm            EQU     (WORD PTR 2)
  10.  
  11. ;****************************************************** Data
  12.  
  13. DATA    SEGMENT WORD PUBLIC
  14.  
  15.         EXTRN   OurSS : WORD            ;value of SS when program began
  16.         EXTRN   LowestSP : WORD         ;lowest value for SP
  17.         EXTRN   HeapHigh : DWORD        ;highest address pointed to by HeapPtr
  18.         EXTRN   HeapPtr : DWORD
  19.         EXTRN   CountsPerTick : WORD
  20.         EXTRN   Counts : WORD
  21.  
  22. DATA    ENDS
  23.  
  24. ;****************************************************** Code
  25.  
  26. CODE    SEGMENT BYTE PUBLIC
  27.  
  28.         ASSUME  CS:CODE,DS:DATA
  29.  
  30.         PUBLIC  ActualSaveInt8, Int8
  31.  
  32. ActualSaveInt8  DD      0               ;stores previous INT 8 handler
  33.  
  34. ;****************************************************** Int8
  35.  
  36. ;procedure Int8;
  37. ;Interrupt service routine used to monitor stack and heap usage
  38.  
  39. Flags   EQU     WORD PTR [BP+6]         ;position of pushed flags
  40.  
  41. Int8    PROC NEAR
  42.  
  43.         PUSH    BP                      ;set up stack frame
  44.         MOV     BP,SP
  45.         PUSH    AX                      ;save registers used
  46.         PUSH    DI
  47.         PUSH    DS
  48.         MOV     AX,SEG DATA             ;set up DS
  49.         MOV     DS,AX
  50.  
  51.         MOV     AX,SS                   ;make sure we're in the right SS
  52.         CMP     AX,OurSS
  53.         JNE     WrongSS
  54.  
  55.         LEA     DI,Flags                ;flags are where SS:SP was when the
  56.         CMP     DI,LowestSP             ;interrupt occurred
  57.         JNB     WrongSS
  58.         MOV     LowestSP,DI
  59.  
  60. WrongSS:
  61.         ;compare HeapPtr and HeapHigh; both are normalized
  62.         MOV     AX,HeapPtr.Segm         ;HeapPtr into AX:DI
  63.         MOV     DI,HeapPtr.Ofst
  64.         CMP     AX,HeapHigh.Segm        ;if the segment is higher,
  65.         JA      IsHigher                ;HeapPtr points higher
  66.         JNE     Done                    ;check offsets only if segments equal
  67.         CMP     DI,HeapHigh.Ofst        ;done if offset isn't higher
  68.         JNA     Done
  69.  
  70. IsHigher:
  71.         MOV     HeapHigh.Ofst,DI        ;HeapHigh = HeapPtr
  72.         MOV     HeapHigh.Segm,AX
  73.  
  74. Done:   INC     Counts                  ;increment counter
  75.         MOV     AX,CountsPerTick        ;see if we need to chain to old ISR
  76.         CMP     Counts,AX
  77.         JAE     Chain
  78.         MOV     AL,20h                  ;send EOI to interrupt controller
  79.         OUT     20h,AL
  80.         POP     DS                      ;restore registers used
  81.         POP     DI
  82.         POP     AX
  83.         POP     BP
  84.         IRET
  85.  
  86. Chain:  MOV     Counts,0                ;reset counter
  87.         POP     DS                      ;restore registers used
  88.         POP     DI
  89.         POP     AX
  90.         POP     BP
  91.         JMP     DWORD PTR ActualSaveInt8 ;chain to old INT $8 handler
  92.  
  93. Int8    ENDP
  94.  
  95. CODE    ENDS
  96.  
  97.         END
  98.